package net.sevear.chaos.view
{
	import com.douban.media.DBRadio;
	
	import flash.display.Bitmap;
	
	import spark.components.Group;
	import spark.components.TextInput;
	
	public class RepeatBtn extends Group
	{
		[Embed(source='/res/repeat.png')]
		private var cycleCls:Class;
		
		private var bmp:Bitmap;
		private var _selected:Boolean = false;
		private var textInput:TextInput;
		private var curCount:int;
		private var repeatTotal:int;
		public function RepeatBtn()
		{
			super();
			this.width = 40;
			this.height = 40;
			
			var cls:Class = cycleCls;
			bmp = new cls() as Bitmap;
			(bmp).smoothing = true;
			this.addElement(bmp);
			
			textInput = new TextInput();
			textInput.verticalCenter = 0;
			textInput.horizontalCenter = 0;
			textInput.enabled = false;
			textInput.maxChars = 2;
			textInput.restrict = "0-9";
		}
		
		public function set selected(value:Boolean):void{
			_selected = value;
			redrawUI();
		}
		
		public function get selected(value:Boolean):Boolean{
			return _selected;
		}
		
		private function redrawUI():void{
			if(_selected){
				textInput.enabled = true;
				
				this.graphics.clear();
				this.graphics.beginFill(0xffc000);
				this.graphics.drawCircle(this.width/2,this.height/2,10);
				this.graphics.endFill();
			}else{
				textInput.enabled = false;
				this.graphics.clear();
				DBRadio.getInstance().repeat(parseInt(textInput.text));
			}
		}
	}
}